﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FatFreeFitness._layout._master
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        string virtualPath = "~/gallery";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RadRotator1.RotatorType = Telerik.Web.UI.RotatorType.SlideShow;
                RadRotator1.DataSource = GetFilesInFolder(virtualPath);// Set datasource
                RadRotator1.DataBind();
            }
        }

        protected List<string> GetFilesInFolder(string folderVirtualPath)
        {
            string filterExpression = string.Empty;
            filterExpression = "*.jpg";
            string physicalPathToFolder = Server.MapPath(folderVirtualPath);// Get the physical path

            
            
            string[] physicalPathsCollection = System.IO.Directory.GetFiles(physicalPathToFolder, filterExpression);// Get all child files of the given folder
            List<string> virtualPathsCollection = new List<string>();// Contains the result

            foreach (String path in physicalPathsCollection)
            {
                // The value of virtualPath will be similar to '~/PathToFolder/Image1.jpg
                string virtualPath = VirtualPathUtility.AppendTrailingSlash(folderVirtualPath) + System.IO.Path.GetFileName(path);
                virtualPathsCollection.Add(virtualPath);
            }
            return virtualPathsCollection;
        }
    }
}